/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.itip;

import java.net.InetAddress;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.sinodata.bsm.common.message.BsmActiveMQFactory;
import com.sinodata.bsm.common.utils.PropertiesUtil;
import com.sinodata.bsm.itip.message.Messenger;
import com.sinodata.bsm.itip.util.DB2ConnectionUtil;
import com.sinodata.bsm.itip.util.SystemContext;
import com.sinodata.bsm.itip.util.TivoliConstants;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author tangli
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-8 下午5:03:48          tangli_ITSM        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public final class ProbeEnv {
    private final static Logger logger = Logger.getLogger(ProbeEnv.class);
    public static Long probeId = 1L;
    public static String probeName = "";
    public static String probeType = "";
    public static String probeIp = "localhost";

    public static String tivoliDriver = "";
    public static String tivoliUrl = "";
    public static String tivoliUser = "";
    public static String tivoliPwd = "";
    public static String tovoliSoap = "";

    public static String mysqlDriver = "";
    public static String mysqlUrl = "";
    public static String mysqlUser = "";
    public static String mysqlPwd = "";

    public static void initEnv() throws Exception {
        //log4j
        PropertyConfigurator.configure("itip-conf/log4j.properties");
        logger.info("itip probe init...");
        //probe
        Properties prop = PropertiesUtil.getProperties("itip-conf/probe-itip.properties");
        probeId = Long.parseLong(prop.getProperty("probe.id"));
        probeName = prop.getProperty("probe.name");
        probeType = prop.getProperty("probe.type");
        probeIp = InetAddress.getLocalHost().getHostName();
        BsmActiveMQFactory.getInstance().init(prop);
        Messenger.getInstance().init(ProbeEnv.probeId);

        tovoliSoap = prop.getProperty("tivoli.soap", "http://127.0.0.1:50857/soap");

        //dbpool
        tivoliDriver = prop.getProperty("tivoli.driver", "");
        tivoliUrl = prop.getProperty("tivoli.url", "");
        tivoliUser = prop.getProperty("tivoli.user", "");
        tivoliPwd = prop.getProperty("tivoli.pwd", "");
        try {
            DB2ConnectionUtil.getInstance().initDBPool(tivoliDriver, tivoliUrl, tivoliUser, tivoliPwd);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("WareHous Init Failed ", e);
        }

        //mysqlpool
        mysqlDriver = prop.getProperty("mysql.driver", "");
        mysqlUrl = prop.getProperty("mysql.url", "");
        mysqlUser = prop.getProperty("mysql.user", "");
        mysqlPwd = prop.getProperty("mysql.pwd", "");
        if ("true".equals(prop.getProperty("mysql.need"))) {
            try {
                DB2ConnectionUtil.getInstance().initMysqlPool(mysqlDriver, mysqlUrl, mysqlUser, mysqlPwd);
            } catch (Exception e) {
                logger.error("Mysql Init Failed", e);
            }
        }

        //system time
        SystemContext.setProperty(TivoliConstants.BEGINTIME, prop.getProperty("begin.time", ""));
        SystemContext.setProperty(TivoliConstants.ENDTIME, prop.getProperty("end.time", ""));

        SystemContext.setProperty(TivoliConstants.SOCKETPORT, prop.getProperty("itip.socket", "9901"));

    }

    public static void main(String[] args) throws Exception {
    }
}
